﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class guoguan_list : System.Web.UI.Page
{
    protected List<Model.LotteryAnnouncementMy> userBuy = null;
    protected string LotteryType = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        LotteryType = Request["lotteryType"].ToString();
        BindTable();
    }
    private void BindTable()
    {
        string userId = "";
        PagedDataSource pds = new PagedDataSource();
        string where = "  LotteryType=" + Request["lotteryType"].ToString() + " and LotteryQs='" + Request["qs"].ToString() + "' and ";
        if (Request["type"].ToString() == "0")
        {
            where += "  IsWin=1 and ";
        }
        else if (Request["type"].ToString() == "1")
        {
            where += "  IsWin=0 and ";
        }
        else if (Request["type"].ToString() == "2")
        {
            if (BLL.CMember.UserLoginInfo() == null)
            {
                System.Web.HttpContext.Current.Response.Write("<script type=\"text/javascript\">alert('请登录');</script>");
                return;
            }
            else
            {
                userId = BLL.CMember.UserLoginInfo().Id.ToString();
                where += "  onemoney='" + userId + "' and ";
            }
        }
        if (Request["userName"] != null && Request["userName"].ToString() != "")
        {
            where += "  onemoney in (select id from CMember where nickname like '%" + Request["userName"].ToString() + "%') and";
        }
        string sql = @"select buyid,convert(decimal(18,0),c.UserID) as onemoney,c.addtime,IsWin,m.oneCount,convert(decimal(18,0),c.LotteryCount)  as twomoney,m.threeMoney,m.fourMoney,m.fiveMoney,m.sixMoney,m.sevenMoney,m.openTime,m.isChipped,m.lotteryType,m.lotteryQS,m.lotteryNo,m.twoCount,m.threeCount,m.fourCount,m.fiveCount,m.sixCount,m.sevenCount,m.summoney,c.id from LotteryChipped c left join  LotteryAnnouncementMy m on c.id=m.buyid and isChipped=1 ";
        DataTable datatable = BLL.LotteryAnnouncementMy.GetPageListBysql("select * from ("+ sql + ")t where "+ where + " 1=1 order by id desc");
        userBuy = BLL.LotteryAnnouncementMy.GetPageListBysqlfrom(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize,  where+ " 1=1 ", "(" + sql + ") t");
        if (userBuy != null && userBuy.Count > 0)
        {
            AspNetPager1.RecordCount = datatable.Rows.Count;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        }
        else
        {
            AspNetPager1.RecordCount = 0;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = 1;
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindTable();
    }

    public string SelectName(object Uid)
    {
        Model.CMember cm = BLL.CMember.GetModel(Convert.ToInt32(Uid));
        if (cm != null)
        {
            return cm.nickname;//用户真实姓名
        }
        else
        {
            return "";
        }
    }
    public string GetZhanJi(int userId,int lotteryType)
    {
        string sql = "select top 1 modellevel as openWinWeek from UsersAccount where user_id='" + userId + "'  and  LotteryType=" + lotteryType;
        Model.LotteryQs zhanJi = BLL.LotteryQs.NewsTopOne(sql);
        if (zhanJi != null)
        {
            return zhanJi.openWinWeek;//用户真实姓名
        }
        else
        {
            return "";
        }
    }
    public int GetWinInfo(int winType, int lotteryId)
    {
        string sql = "select top 1 * from LotteryChippedWinInfo where chippedId='" + lotteryId + "'";
        Model.LotteryAnnouncementMy win = BLL.LotteryAnnouncementMy.NewsTopOne(sql);
        if (win != null)
        {
            if (winType == 1)
            {
                return win.oneCount;
            }
            else if(winType == 2)
            {
                return win.twoCount;
            }
            else if (winType == 3)
            {
                return win.threeCount;
            }
            else if (winType == 4)
            {
                return win.fourCount;
            }
            else if (winType == 5)
            {
                return win.fiveCount;
            }
            else if (winType == 6)
            {
                return win.sixCount;
            }
            else if (winType ==7)
            {
                return win.sevenCount;
            }
            else
            {
                return 0;
            }

        }
        else
        {
            return 0;
        }
    }
    public string ViewModelLevel(long UserId)
    {

        string divs = BLL.LotteryChipped.ViewModelLevel(UserId);
        return divs;

    }
}